﻿using System;
using System.Web;
using System.Web.Configuration;
using Core.Library;

namespace DataObject
{
    public class Constants
    {
        public static string All_Column = "*";
        public static string Category_FieldList = "CategoryId, Name, Priority, Url, ImagePath, ParentId";
        public static string Product_FieldList  = "ProductId, CategoryId, Code, Name, Description, UnitPrice, SpecialPrice, Status, Type, Url";
        public static string Order_FieldList    = "OrderId, CustomerId, Status, TotalValue, OrderDate, RequiredDate, Note";
         
        public static string Avatar_Default     = "/images/avatar.gif";        

        public static string ConnectionString           = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        public static string ThumbImage                 = GetStringFromWebConfig("ThumbImage");
        public static string ThumbImageSizeList         = GetStringFromWebConfig("ThumbSizeList");
        public static string ThumbImageSizeListFilter   = GetStringFromWebConfig("ThumbImageSizeListFilter");

        public static string ThumbImageSizeLargeDetail  = GetStringFromWebConfig("ThumbSizeLargeDetail");
        public static string ThumbImageSizeSmallDetail  = GetStringFromWebConfig("ThumbSizeSmallDetail");
        public static int CutString                     = GetValueFromWebConfig("CutString");   

        public static int GetValueFromWebConfig(string configName)
        {
            return ConvertUtility.ToInt32(WebConfigurationManager.AppSettings[configName]);
        }

        public static string GetStringFromWebConfig(string configName)
        {
            try { return WebConfigurationManager.AppSettings[configName]; }
            catch { return string.Empty; }            
        }

        private static string basePath = string.Empty;
        public static string BaseUrl
        {
            get
            {
                if (string.IsNullOrEmpty(basePath))
                {
                    basePath = HttpContext.Current.Request.ApplicationPath;
                    if (!basePath.EndsWith("/"))
                    {
                        basePath += "/";
                    }
                }
                return basePath;
            }
        }

        //========================================================================================================================================//

        public static int PARENT_ROOT   = 0;
        public static int NOT_ACTIVE    = 0;
        public static int ACTIVE        = 1;        
        public static int ALL           = -1;

        public static string SITE_DOMAIN = " | kmt.vn";
        public static string SITE_TITLE = " | Sơ Mi Xuất Khẩu";
        public static string SITE_DESCRIPTION = "";
        public static string SITE_KEYWORD = "";

        public const long CACHE_30_MINUTE   = 1800;
        public const long CACHE_1_HOUR      = 3600;
        public const long CACHE_2_HOUR      = 7200;

        public const long CACHE_1_DAY       = 864000;
        public const long CACHE_1_Year      = 2592000000; 


        public const long CACHE_EXPIRE_SHORT = 120; //2 minutes

        /// <summary>
        /// {key}_LastUpdate
        /// </summary>
        public const string CACHE_NAME_LAST_UPDATE = "{0}_LastUpdate";

        public const string DATA_CACHE_CATEGORY     = "data";
        public const string LIST_CACHE_CATEGORY     = "list";
        public const string DETAILS_CACHE_CATEGORY  = "detail";
        public const string COMMENT_CACHE_CATEGORY  = "comment";


        public const string SESSION_CUSTOMER      = "session_customer";
        public const string SESSION_USERNAME      = "session_username";
        public const string SESSION_MOBILE        = "session_mobile";
        public const string SESSION_AVATAR        = "session_avatar";
        public const string SESSION_IS_LOGGED_IN  = "session_is_logged_in";
        public const string SESSION_SHOPPING_CART = "session_shopping_cart";

        public static string GetProductType(int type)
        {
            switch (type)
            {
                case 1:
                    return "<span style=\"color:red\">Hết hàng</span>";
                case 2:
                    return "<span style=\"color:brown\">Đặt hàng</span>";
                case 4:
                    return "<span style=\"color:green\">Hàng có sẵn</span>";
            }
            return "-";
        }
    }

    //========================================================================================================================================//
    public enum StaticType
    {
        Category = 1,
        Article  = 2
    }

    public enum AdvType
    {
        Single    = 1,
        Multiple  = 2,
        SlideShow = 3,
        Partner   = 4
    }

    public enum OnlineType
    {
        Top  = 1,
        Left = 2
    }

    public enum CategoryType
    {
        Product  = 1,
        Article  = 2,
        Image    = 3,
        Adv      = 4,
        Static   = 5,
        Category = 6,
    }

    public enum CommentType
    {
        IsWaitingForPublish = 1,
        IsPublished         = 2
    }

    public enum OrderStatus
    {
        OrderTemp     = 1,
        OrderComplete = 2,
        OrderDeleted  = 4
    }

    public enum ProductStatus
    {
        IsDraft     = 1,
        IsPublished = 2,
        Highlight   = 4
    }
    //========================================================================================================================================//
}
